<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="时间" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="date">
              <g-year-picker
                placeholder="请选择时间"
                v-model="model.date"
              ></g-year-picker>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-input v-model="model.projectName" placeholder="请输入名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classess">
              <j-dict-select-tag type="list" v-model="model.classess" dictCode="RESEARCEH_ZDBZ_CLASSESS" placeholder="请选择类别"  @change="getTotalScore"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="积分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalScore">
              <a-input-number v-model="model.totalScore" placeholder="请输入积分" style="width: 100%":disabled="true" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="备注" :labelCol="{span:2}" :wrapperCol="{span:22}" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注" ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
      <!-- 子表单区域 -->
    <research-member-list ref="memberListRef" v-model="memberListTable.dataSource" :project-info="model"  :disabled="formDisabled" :loading="memberListTable.loading"></research-member-list>
  </a-spin>
</template>

<script>

  import { getAction } from '@/api/manage'
  import { FormTypes,getRefPromise,VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
  import { JEditableTableModelMixin } from '@/mixins/JEditableTableModelMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import { GfxyResearchMemberListMixin } from '@/mixins/GfxyResearchMemberListMixin'
  import GYearPicker from '@views/gfxy/common/GYearPicker'
  import researchMemberList from '@views/gfxy/common/researchMemberList'

  export default {
    name: 'ResearchDzbzForm',
    mixins: [GfxyResearchMemberListMixin],
    components: {
      GYearPicker,researchMemberList
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        model:{
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
           date: [
              { required: true, message: '请输入时间!'},
           ],
           projectName: [
              { required: true, message: '请输入名称!'},
           ],
           classess: [
              { required: true, message: '请输入类别!'},
           ],
           totalScore: [
              { required: true, message: '请输入积分!'},
           ],
        },
        refKeys: ['researchMemberList', ],
        tableKeys:['researchMemberList', ],
        activeKey: 'researchMemberList',
        // 科研成员列表

        url: {
          add: "/research/researchDzbz/add",
          edit: "/research/researchDzbz/edit",
          queryById: "/research/researchDzbz/queryById",
          getTotalScore: "/research/researchDzbz/getTotalScore",
          researchMemberList: {
            list: '/research/researchDzbz/queryResearchMemberListByMainId'
          },
        }
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      projectType:{
        type: Number,
        required: true,
      },
      date:{
        type: String,
        required: true,
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
    },
    methods: {
      getTotalScore(){
        let that = this;
        if( this.model.classess != undefined ){
          this.confirmLoading = true;
          getAction(this.url.getTotalScore,{classess: this.model.classess}).then((res) => {
            if (res.success) {
              this.model.totalScore = res.result;
              this.$nextTick(()=>{
                this.$refs.memberListRef.getScore();
              })
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }

          }).catch(()=>{
            this.$message.warning("出错！");
          }).finally(() => {
            this.confirmLoading = false;
          })
        }
      },

    }
  }
</script>

<style scoped>
</style>